package com.example.oss.controller;

import javax.annotation.Resource;

import java.util.List;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.example.oss.entity.Stock;
import com.example.oss.entity.User;
import com.example.oss.returns.Result;
import com.example.oss.service.StockService;
import com.example.oss.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/goods/Stock")
@Api(tags = "商品信息")
public class StockController {

    @Resource
    private StockService stockService;

    @Resource
    private UserService userService;

    @GetMapping("fetch-pages")
    @ApiOperation("根据id获取商品")
    @SuppressWarnings("all")
    public Result fetchPages(@RequestParam("id") Integer id) {
        Stock stock = stockService.getById(id);
        return new Result(stock);
    }

    @GetMapping("all")
    @ApiOperation("获取商品列表")
    public Result getAll() {
        List<Stock> list = stockService.list();
        return new Result(list);
    }

    @GetMapping("add")
    @ApiOperation("新增商品")
    public Result insert() {
        User user = new User();
        user.setId(1L);
        user.setUserName("加一");
        boolean save = userService.save(user);
        return new Result(save);
    }
}
